/* 基础样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #333;
}

/* 游戏容器 */
.game-container {
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
    padding: 20px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
}

/* 游戏头部 */
.game-header {
    text-align: center;
    margin-bottom: 30px;
}

.game-header h1 {
    font-size: 2.5rem;
    color: #4a5568;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.score-display, .time-display {
    background: #f7fafc;
    padding: 10px 15px;
    border-radius: 10px;
    border: 2px solid #e2e8f0;
    font-weight: bold;
}

.label {
    color: #718096;
    margin-right: 5px;
}

#score, #time {
    color: #2d3748;
    font-size: 1.2rem;
}

.restart-btn {
    background: linear-gradient(135deg, #ff6b6b, #ee5a24);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 10px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(238, 90, 36, 0.3);
}

.restart-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(238, 90, 36, 0.4);
}

/* 游戏网格 */
.game-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: 4px;
    width: 100%;
    max-width: 480px;
    aspect-ratio: 1;
    margin: 0 auto;
    background: #2d3748;
    padding: 10px;
    border-radius: 15px;
    box-shadow: inset 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* 游戏单元格 */
.ghost-cell {
    background: #f7fafc;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
    backface-visibility: hidden;
    position: relative;
    overflow: hidden;
}

.ghost-cell:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.ghost-cell.selected {
    background: #ffd93d;
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(255, 217, 61, 0.6);
    z-index: 10;
}

.ghost-cell.matching {
    animation: matchPulse 0.5s ease-in-out;
}

.ghost-cell.falling {
    transition: transform 0.4s cubic-bezier(0.55, 0, 0.1, 1);
}

/* 小鬼图标样式 */
.ghost-icon {
    width: 80%;
    height: 80%;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-weight: bold;
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

/* 5种不同类型的小鬼 */
.ghost-type-0 { 
    background: linear-gradient(135deg, #ff6b6b, #ee5a24);
    box-shadow: 0 2px 8px rgba(255, 107, 107, 0.4);
}
.ghost-type-1 { 
    background: linear-gradient(135deg, #4ecdc4, #44a08d);
    box-shadow: 0 2px 8px rgba(78, 205, 196, 0.4);
}
.ghost-type-2 { 
    background: linear-gradient(135deg, #45b7d1, #96c93d);
    box-shadow: 0 2px 8px rgba(69, 183, 209, 0.4);
}
.ghost-type-3 { 
    background: linear-gradient(135deg, #f093fb, #f5576c);
    box-shadow: 0 2px 8px rgba(240, 147, 251, 0.4);
}
.ghost-type-4 { 
    background: linear-gradient(135deg, #4facfe, #00f2fe);
    box-shadow: 0 2px 8px rgba(79, 172, 254, 0.4);
}

/* 动画效果 */
@keyframes matchPulse {
    0%, 100% { 
        transform: scale(1); 
        box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
    }
    50% { 
        transform: scale(1.2); 
        box-shadow: 0 0 20px rgba(255, 255, 255, 0.8);
    }
}

@keyframes fadeOut {
    0% { 
        opacity: 1; 
        transform: scale(1) rotate(0deg); 
    }
    100% { 
        opacity: 0; 
        transform: scale(0.3) rotate(180deg); 
    }
}

@keyframes slideDown {
    0% { 
        transform: translateY(-100%) scale(0.8); 
        opacity: 0; 
    }
    100% { 
        transform: translateY(0) scale(1); 
        opacity: 1; 
    }
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-10px);
    }
    60% {
        transform: translateY(-5px);
    }
}

@keyframes glow {
    0%, 100% {
        box-shadow: 0 0 5px rgba(255, 255, 255, 0.3);
    }
    50% {
        box-shadow: 0 0 20px rgba(255, 255, 255, 0.8);
    }
}

/* 选中状态增强效果 */
.ghost-cell.selected .ghost-icon {
    animation: glow 1s ease-in-out infinite;
}

/* 匹配状态增强效果 */
.ghost-cell.matching .ghost-icon {
    animation: matchPulse 0.5s ease-in-out, fadeOut 0.3s ease-in-out 0.2s forwards;
}

/* 新生成的小鬼动画 */
.ghost-cell.new-ghost .ghost-icon {
    animation: slideDown 0.4s ease-out, bounce 0.6s ease-out 0.4s;
}

/* 下落动画 */
.ghost-cell.falling .ghost-icon {
    animation: slideDown 0.4s cubic-bezier(0.55, 0, 0.1, 1);
}

/* 分数更新动画 */
@keyframes scoreUpdate {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); color: #ffd93d; }
    100% { transform: scale(1); }
}

.score-update {
    animation: scoreUpdate 0.3s ease-in-out;
}

/* 状态消息样式 */
.status-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 15px 25px;
    border-radius: 10px;
    font-size: 1.2rem;
    font-weight: bold;
    z-index: 999;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.status-message.show {
    opacity: 1;
}

/* 增强游戏信息区域的视觉效果 */
.game-info {
    background: rgba(255, 255, 255, 0.1);
    padding: 15px;
    border-radius: 15px;
    backdrop-filter: blur(10px);
}

.score-display, .time-display {
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid rgba(255, 255, 255, 0.3);
    transition: all 0.3s ease;
}

.score-display:hover, .time-display:hover {
    background: rgba(255, 255, 255, 1);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* 游戏覆盖层 */
.game-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.overlay-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.overlay-content h2 {
    margin-bottom: 15px;
    color: #2d3748;
}

.overlay-content p {
    margin-bottom: 25px;
    color: #718096;
}

.continue-btn {
    background: linear-gradient(135deg, #4ecdc4, #44a08d);
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 10px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
}

.continue-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(68, 160, 141, 0.4);
}

/* 响应式设计 */
@media (max-width: 768px) {
    .game-container {
        padding: 15px;
        margin: 10px;
    }
    
    .game-header h1 {
        font-size: 2rem;
    }
    
    .game-info {
        justify-content: center;
        gap: 10px;
    }
    
    .game-grid {
        max-width: 90vw;
        max-height: 90vw;
    }
    
    .ghost-icon {
        font-size: 1.2rem;
    }
}

@media (max-width: 480px) {
    .game-container {
        padding: 10px;
        margin: 5px;
    }
    
    .game-header h1 {
        font-size: 1.8rem;
        margin-bottom: 15px;
    }
    
    .game-info {
        flex-direction: column;
        align-items: center;
        gap: 8px;
    }
    
    .score-display, .time-display {
        padding: 8px 12px;
        font-size: 0.9rem;
        min-width: 120px;
        text-align: center;
    }
    
    .restart-btn {
        padding: 10px 16px;
        font-size: 0.9rem;
    }
    
    .game-grid {
        max-width: 95vw;
        max-height: 95vw;
        gap: 2px;
        padding: 8px;
    }
    
    .ghost-cell {
        border-radius: 6px;
    }
    
    .ghost-icon {
        font-size: 1rem;
    }
    
    /* 优化触摸区域 */
    .ghost-cell {
        min-height: 40px;
        min-width: 40px;
    }
    
    /* 状态消息在小屏幕上的优化 */
    .status-message {
        font-size: 1rem;
        padding: 12px 20px;
        max-width: 90vw;
        text-align: center;
    }
}

/* 超小屏幕优化 */
@media (max-width: 360px) {
    .game-header h1 {
        font-size: 1.5rem;
    }
    
    .game-grid {
        gap: 1px;
        padding: 6px;
    }
    
    .ghost-icon {
        font-size: 0.9rem;
    }
    
    .score-display, .time-display {
        font-size: 0.8rem;
        padding: 6px 10px;
    }
}

/* 横屏模式优化 */
@media (max-height: 600px) and (orientation: landscape) {
    .game-container {
        padding: 10px;
        max-width: none;
        display: flex;
        flex-direction: row;
        align-items: flex-start;
        gap: 20px;
    }
    
    .game-header {
        flex: 0 0 200px;
        margin-bottom: 0;
    }
    
    .game-main {
        flex: 1;
        display: flex;
        justify-content: center;
    }
    
    .game-grid {
        max-width: 400px;
        max-height: 400px;
    }
    
    .game-header h1 {
        font-size: 1.5rem;
        margin-bottom: 15px;
    }
    
    .game-info {
        flex-direction: column;
        gap: 10px;
    }
}

/* 高DPI屏幕优化 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .ghost-cell {
        border: 0.5px solid rgba(255, 255, 255, 0.1);
    }
    
    .ghost-icon {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* 性能优化 */
.game-grid {
    /* 启用硬件加速 */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    
    /* 优化渲染 */
    contain: layout style paint;
}

.ghost-cell {
    /* 优化动画性能 */
    will-change: transform, opacity;
    contain: layout style paint;
    
    /* 减少重绘 */
    isolation: isolate;
}

.ghost-icon {
    /* 优化文本渲染 */
    text-rendering: optimizeSpeed;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    
    /* 防止选择 */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    
    /* 防止拖拽 */
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
}

/* 加载状态 */
.game-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 200px;
    font-size: 1.2rem;
    color: #666;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 错误状态 */
.game-error {
    text-align: center;
    padding: 40px 20px;
    color: #e74c3c;
    background: rgba(231, 76, 60, 0.1);
    border-radius: 10px;
    margin: 20px 0;
}

/* 无障碍优化 */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 高对比度模式 */
@media (prefers-contrast: high) {
    .ghost-cell {
        border: 2px solid #000;
    }
    
    .ghost-cell.selected {
        border: 3px solid #ff0000;
        background: #ffff00;
    }
}

/* 暗色主题支持 */
@media (prefers-color-scheme: dark) {
    body {
        background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    }
    
    .game-container {
        background: rgba(44, 62, 80, 0.95);
        color: #ecf0f1;
    }
    
    .game-header h1 {
        color: #ecf0f1;
    }
    
    .score-display, .time-display {
        background: rgba(52, 73, 94, 0.8);
        color: #ecf0f1;
        border-color: rgba(255, 255, 255, 0.2);
    }
    
    .game-grid {
        background: #34495e;
    }
    
    .ghost-cell {
        background: #2c3e50;
    }
}